Skip to content

feat(deploy): pass the restricted Pod Security Standard - #140

Merged
Jumziey merged 1 commit into
mainfrom
feat/restricted-pod-security
Nov 21, 2026
Merged

Jumziey merged 1 commit into
mainfrom
feat/restricted-pod-security

Conversation

@Jumziey

@Jumziey Jumziey commented Nov 21, 2026

Copy link
Copy Markdown
Contributor

Closes #134

Summary

Each shipped container now passes the restricted Pod Security Standard.

 backend   (UID 1001, from the image)
+  securityContext: no privilege escalation, drop ALL, runAsNonRoot, RuntimeDefault
+  readOnlyRootFilesystem: true
+  emptyDir -> /tmp              # Vert.x file cache; no start without it

 frontend
-  nginx:alpine                  # root, port 80, writes env-config.js to the static files
+  nginxinc/nginx-unprivileged   # UID 101, port 8080
+  securityContext: same as backend, with readOnlyRootFilesystem: true
+  emptyDir -> /tmp              # env-config.js (through a link), pid file, temp paths
   Service port 80 -> targetPort http    # no change for Ingress or HTTPRoute

 valkey    (upstream image starts as root)
+  securityContext: same four fields
+  runAsUser: 999, runAsGroup: 1000      # the `valkey` user of the 8-alpine image

The new PR check, in the manifests job:

ci/check-restricted-pod-security.sh
  create a kind cluster with its own kubeconfig
  label the namespace: enforce=restricted, warn=restricted
  control: a Deployment with no securityContext must fail
  kubectl apply --dry-run=server --warnings-as-errors -k overlays/quickstart
  delete the cluster

enforce rejects only Pods, not a Deployment with a bad pod template. Thus, the check uses warn and makes each warning an error.

Other changes:

  • compose.yml and compose.quickstart.yml map the frontend port 8080.
  • compose.yml starts nginx through the image entrypoint. The old command bypassed the entrypoint, so env-config.js was not generated.
  • docs/deployment.md has a "Pod security" section. ADR 0044 records the trade-offs.

Evidence

  • Before: bash ci/check-restricted-pod-security.sh on the old manifests:

    Warning: would violate PodSecurity "restricted:latest": allowPrivilegeEscalation != false (container "backend" ...
    Warning: would violate PodSecurity "restricted:latest": ... (container "frontend" ...
    Warning: would violate PodSecurity "restricted:latest": ... (container "valkey" ...
    error: 3 warnings received
    

    After:

    PASS: control Deployment without securityContext is rejected
    PASS: the quickstart overlay passes the restricted Pod Security Standard
    
  • Before: bash frontend/ci/bin/test-build-version-image.sh with the new checks on the old image: exit 56, no listener on port 8080.

    After: 14 checks pass. The new one:

    PASS: runs as user 101 on a read-only root filesystem and serves the runtime config
    
  • Before: backend with readOnlyRootFilesystem: true and no writable /tmp, on a kind cluster that enforces restricted:

    IllegalStateException: Unable to create folder at path '/tmp/vertx-cache/...'
    Caused by: java.nio.file.FileSystemException: /tmp/vertx-cache: Read-only file system
    

    After: with the emptyDir at /tmp, all five pods run. The backend is ready and scrapes, the frontend serves / and /env-config.js, and Valkey saves a snapshot. Each container has CapEff: 0 and NoNewPrivs: 1. This run was by hand, with the frontend image of this branch and the backend edge image.

  • Frontend tests: 252 pass. kubeconform: all three compositions are valid.

  • The backend Gradle suite was not run locally. No backend code changed.

Merge Danger

Door: two-way

A revert restores the old manifests and the old image recipe. But each frontend image that is published from this change listens on port 8080 and stays published.

Blast Radius: deployers

  • Image pins. deploy/k8s/base/kustomization.yaml pins the frontend to 0.0.46, which runs as root on port 80. The new manifests do not start that image. After this merge, the quickstart overlay on main gives a frontend pod that does not start. The release job bumps the pins on main after a stable tag, so the tree at the tag itself still has the old pins. Before the next tag, pin the two images to the sha-<short> tag of this merge commit.
  • Frontend port. An operator who runs the frontend image with their own manifest or port mapping must change port 80 to port 8080.
  • Valkey IDs. UID 999 and GID 1000 are those of valkey/valkey:8-alpine. A different Valkey image can need different IDs.
  • No automatic check for the backend limits. The PR check is a dry run and starts no pods. A new dependency that writes outside /tmp fails only in a cluster.

Each shipped container (backend, frontend, bundled Valkey) now sets
allowPrivilegeEscalation: false, drops all capabilities, sets
runAsNonRoot: true, and uses the RuntimeDefault seccomp profile.

- Backend: read-only root filesystem with an emptyDir at /tmp. Vert.x
  creates its file cache there at start, and the backend does not start
  without it.
- Frontend: the image moves to nginxinc/nginx-unprivileged (UID 101,
  port 8080). The served env-config.js is a link to /tmp/env-config.js,
  so the root filesystem is read-only with an emptyDir at /tmp. The
  Service keeps port 80.
- Valkey: the upstream image starts as root, so the manifest sets
  runAsUser 999 and runAsGroup 1000.
- compose: map the frontend port 8080, and start nginx through the image
  entrypoint so that env-config.js is written.
- CI: the manifests job applies the quickstart overlay to a kind cluster
  as a server-side dry run and fails on a Pod Security warning. The
  frontend image check starts the image with the limits of the
  Deployment.

The frontend image now listens on port 8080, not port 80. The manifests
do not start a frontend image from before this change, so the image pins
must move to an image with this change before the manifests are
released. See docs/adr/0044.

Closes #134
@Jumziey
Jumziey force-pushed the feat/restricted-pod-security branch from bf78bfe to f4c77f5 Compare November 21, 2026 11:11
@Jumziey
Jumziey merged commit 89f61c5 into main Nov 21, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add securityContext to the Kubernetes manifests (restricted Pod Security Standard)

1 participant